﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CloudTalk.Data;

namespace Com.CloudTalk.Controller
{
    public class CTEvent
    {
        public int ID { get; set; }
        public string Text { get; set; }
        public CTClient Sender { get; set; }
        public CTClient Recipient { get; set; }
        public EventType Type { get; set; }
        public DateTime Timestamp { get; set; }

        public CTEvent(Event _origEvent)
        {
            this.ID = _origEvent.ID;
            this.Text = _origEvent.Text;
            this.Sender = new CTClient(_origEvent.Sender.Name, _origEvent.Sender.Email);
            this.Recipient = new CTClient(_origEvent.Recipient.Name, _origEvent.Recipient.Email);
            this.Timestamp = _origEvent.Timestamp;

            Type evtType = _origEvent.GetType();

            if (evtType == typeof(MessageEvent))
            {
                this.Type = EventType.Message;
            }
            else if (evtType == typeof(LeaveRoomEvent))
            {
                this.Type = EventType.LeaveRoom;
            }
            else if (evtType == typeof(EnterRoomEvent))
            {
                this.Type = EventType.EnterRoom;
            }
            else if (evtType == typeof(RoomSpaceAvailableEvent))
            {
                this.Type = EventType.RoomSpaceAvailable;
            }
            else if (evtType == typeof(QueueSizeChangedEvent))
            {
                this.Type = EventType.QueueSizeChanged;
            }
            else
            {
                throw new ApplicationException("Invalid event type found");
            }
        }
    }

    public enum EventType
    {
        Message,
        LeaveRoom,
        EnterRoom,
        RoomSpaceAvailable,
        QueueSizeChanged
    }
}
